<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="福利标题" prop="title">
				<el-input v-model="form.title" placeholder="福利标题" maxlength="80"></el-input>
			</el-form-item>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="排序号" prop="sortNo">
						<el-input-number v-model="form.sortNo" placeholder="排序号"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="人员姓名" prop="userId">
						<select-hr-user-dialog v-model:userId="form.userId" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="发放年度" prop="year">
						<el-date-picker v-model="form.year" placeholder="发放年度" type="year" value-format="YYYY"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="发放月份" prop="month">
						<el-select v-model="form.month" clearable filterable>
							<el-option value="1" label="一月"></el-option>
							<el-option value="2" label="二月"></el-option>
							<el-option value="3" label="三月"></el-option>
							<el-option value="4" label="四月"></el-option>
							<el-option value="5" label="五月"></el-option>
							<el-option value="6" label="六月"></el-option>
							<el-option value="7" label="七月"></el-option>
							<el-option value="8" label="八月"></el-option>
							<el-option value="9" label="九月"></el-option>
							<el-option value="10" label="十月"></el-option>
							<el-option value="11" label="十一月"></el-option>
							<el-option value="12" label="十二月"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="福利类型" prop="welfareType">
						<sc-select v-model="form.welfareType" :params="{code:'welfareType'}" :apiObj="$API.hr.hrDic.getHrDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="福利金额" prop="amount">
						<el-input-number v-model="form.amount" placeholder="薪级工资"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明">
				<el-input v-model="form.remark" placeholder="备注说明" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectHrUserDialog from "@/views/module/selectHrUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectHrUserDialog,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			btName: "保存",
			titleMap: {
				add: '添加福利记录',
				edit: '编辑福利记录',
				show: '查看'
			},
			fileList: [],
			apiObj: this.$API.file.attach.uploadFile,
			templateList: [],
			templates: [],
			form: {
				recordId: "",
				title:"",
				sortNo: 0,
				userId: "",
				year: "",
				month: "",
				welfareType:"",
				amount:0,
				remark:""
			},
			rules: {
				userId: [
					{required: true, message: '人员不能为空', trigger: 'change'}
				],
				year: [
					{required: true, message: '薪资年度不能为空'}
				],
				mouth: [
					{required: true, message: '薪资月份不能为空'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.hr.hrWelfare.insertHrWelfareRecord.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.hr.hrWelfare.updateHrWelfareRecord.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.sortNo = data.sortNo
			this.form.userId = data.userId
			this.form.year = data.year
			this.form.month = data.month
			this.form.title = data.title
			this.form.welfareType = data.welfareType
			this.form.amount = data.amount
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
